<?php

/**
 * This is the model class for table "modality".
 *
 * The followings are the available columns in table 'modality':
 * @property integer $id
 * @property string $modality_name
 * @property string $type_of_modality
 * @property string $description
 *
 * The followings are the available model relations:
 * @property SuccessfulCase[] $successfulCases
 * @property Testimony[] $testimonies
 * @property Treatment[] $treatments
 */
class Modality extends CActiveRecord
{

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
		const dm='Diagnostic Modality';
        const tm='Treatment Modality';
	/**
	 * @return string the associated database table name
	 */    
	         
      public function getTypeOfModalityOption(){
              return array(
                        self::dm=>'Diagnostic Modality',
                        self::tm=>'Treatment Modality',
                        );    
}    
     public function tableName()
	{
		return 'modality';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('modality_name, type_of_modality, description', 'required'),
			array('modality_name', 'length', 'max'=>50),
			array('type_of_modality', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, modality_name, type_of_modality, description', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'successfulCases' => array(self::HAS_MANY, 'SuccessfulCase', 'modality_id'),
			'testimonies' => array(self::HAS_MANY, 'Testimony', 'modality_id'),
			'treatments' => array(self::HAS_MANY, 'Treatment', 'modality_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'modality_name' => 'Modality Name',
			'type_of_modality' => 'Type Of Modality',
			'description' => 'Description',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('modality_name',$this->modality_name,true);
		$criteria->compare('type_of_modality',$this->type_of_modality,true);
		$criteria->compare('description',$this->description,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}